package com.example.testapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ProjectPhaseActivity extends AppCompatActivity {

    String[] name = new String[]{"不限", "构思", "立项", "设计", "文件草拟", "招标", "截标后", "主体工程中标/开工", "主体工程封顶", "室内装修/封顶后分包工程", "分包工程中标", "项目已完成","不111限", "222", "333", "4444", "76857", "666", "截标后", "7575575", "主体工程封顶", "室内装修/封顶后分包工程", "分包工程中标", "项目已完成"};
    Map<Integer, Boolean> checkMap;
    private List<String> listDatas = new ArrayList<>();
    String checkName = "";
    private TextView tvFinish;
    private LocalBroadcastManager localBroadcastManager;
    ImageView ivBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project_phase);

        RecyclerView recyclerView = findViewById(R.id.recyclerViewProjectPhase);
        List<Category> categoryList = new ArrayList<>();
        for (int i = 0; i < name.length; i++) {
            Category category = new Category();
            category.setCategory(name[i]);
            categoryList.add(category);
        }
        final ProjectPhaseRecyclerViewAdapter projectPhaseRecyclerViewAdapter = new ProjectPhaseRecyclerViewAdapter(categoryList);
        Log.e("TAG", String.valueOf(categoryList.size()));
        LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(projectPhaseRecyclerViewAdapter);

        checkMap = projectPhaseRecyclerViewAdapter.getMap();
        tvFinish = findViewById(R.id.tvFinish);
        ivBack = findViewById(R.id.ivBack1);


        tvFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                listDatas.clear();
                for (int i = 0; i < name.length; i++) {
                    if (checkMap.get(i)) {
                        listDatas.add(name[i]);
                    }
                }

                for (int i = 0; i < listDatas.size(); i++) {
                    checkName += listDatas.get(i);
                }

                localBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
                Intent intent = new Intent("com.example.LOCAL");
                final String str = checkName;
                intent.putExtra("str", str);
                localBroadcastManager.sendBroadcast(intent);
                finish();

            }
        });

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
